
function sport_delete(id){
	alert("Function will coming soon.");
}

function team_delete(id){
	alert("Function will coming soon.");
}

function currency_delete(id){
	jQuery.post(BASE_URI+'admin/dataman/general/currency_delete',{id:id},function(res){
		reload();
	});
}

function coin_package_delete(id){
	jQuery.post(BASE_URI+'admin/dataman/general/coin_package_delete',{id:id},function(res){
		reload();
	});
}

function sport_edit(id){
	jQuery.post(BASE_URI+'admin/dataman/general/edit_sport',{id:id},function(res){
		jQuery('#dialog').html(res);
		jQuery('#dialog').dialog(
			{
				 width: 650,
				 resizable: false,
				 height:200,
				 title: 'Edit sport' 
			}
		);
	});
}

function add_sport(){
	jQuery.post(BASE_URI+'admin/dataman/general/add_sport',{},function(res){
		jQuery('#dialog').html(res);
		jQuery('#dialog').dialog(
			{
				 width: 650,
				 resizable: false,
				 height:200,
				 title: 'Add sport' 
			}
		);
	});
}

function add_team(){
	jQuery.post(BASE_URI+'admin/dataman/general/add_team',{},function(res){
		jQuery('#dialog').html(res);
		jQuery('#dialog').dialog(
			{
				 width: 650,
				 resizable: false,
				 height:200,
				 title: 'Add team' 
			}
		);
	});
}

function team_edit(id){
	jQuery.post(BASE_URI+'admin/dataman/general/edit_team',{id:id},function(res){
		jQuery('#dialog').html(res);
		jQuery('#dialog').dialog(
			{
				 width: 650,
				 resizable: false,
				 height:200,
				 title: 'Edit team' 
			}
		);
	});
}

function add_currency(){
	jQuery.post(BASE_URI+'admin/dataman/general/add_currency',{},function(res){
		jQuery('#dialog').html(res);
		jQuery('#dialog').dialog(
			{
				 width: 650,
				 resizable: false,
				 height:200,
				 title: 'Add currency' 
			}
		);
	});
}

function currency_edit(id){
	jQuery.post(BASE_URI+'admin/dataman/general/edit_currency',{id:id},function(res){
		jQuery('#dialog').html(res);
		jQuery('#dialog').dialog(
			{
				 width: 650,
				 resizable: false,
				 height:200,
				 title: 'Edit currency' 
			}
		);
	});
}

function add_coin_packages(){
	jQuery.post(BASE_URI+'admin/dataman/general/add_coin_packages',{},function(res){
		jQuery('#dialog').html(res);
		jQuery('#dialog').dialog(
			{
				 width: 650,
				 resizable: false,
				 height:300,
				 title: 'Add Coin Packages' 
			}
		);
	});
}

function coin_package_edit(id){
	jQuery.post(BASE_URI+'admin/dataman/general/add_coin_packages',{id:id},function(res){
		jQuery('#dialog').html(res);
		jQuery('#dialog').dialog(
			{
				 width: 650,
				 resizable: false,
				 height:300,
				 title: 'Edit Coin Packages' 
			}
		);
	});
}

function add_category(){
	jQuery.post(BASE_URI+'admin/dataman/general/add_category',{},function(res){
		jQuery('#dialog').html(res);
		jQuery('#dialog').dialog(
			{
				 width: 650,
				 resizable: false,
				 height:200,
				 title: 'Add Category' 
			}
		);
	});
}

function edit_default_category(id){
	jQuery.post(BASE_URI+'admin/dataman/general/add_category',{id:id},function(res){
		jQuery('#dialog').html(res);
		jQuery('#dialog').dialog(
			{
				 width: 650,
				 resizable: false,
				 height:200,
				 title: 'Edit Category' 
			}
		);
	});
}

function delete_default_category(id){
	jQuery.post(BASE_URI+'admin/dataman/general/delete_default_category',{id:id},function(res){
		reload();
	});
}

function delete_default_event(id){
	jQuery.post(BASE_URI+'admin/dataman/general/delete_default_event',{id:id},function(res){
		reload();
	});
}

function add_event(){
	jQuery.post(BASE_URI+'admin/dataman/general/add_event',{},function(res){
		jQuery('#dialog').html(res);
		jQuery('#dialog').dialog(
			{
				 width: 650,
				 resizable: false,
				 height:200,
				 title: 'Add Event' 
			}
		);
	});
}

function edit_default_event(id){
	jQuery.post(BASE_URI+'admin/dataman/general/add_event',{id:id},function(res){
		jQuery('#dialog').html(res);
		jQuery('#dialog').dialog(
			{
				 width: 650,
				 resizable: false,
				 height:200,
				 title: 'Edit Event' 
			}
		);
	});
}

jQuery(document).ready(function() {
	var optionsSport = { 
		beforeSubmit:function(formData, jqForm, options){ 
						jQuery('#name_error').hide();
						if(isEmpty(jQuery('#name').val())){
							jQuery('#name_error').show();
							return false;
						} 
						return true;
					},   
		success:function(responseText, statusText, xhr, $form){
			if(responseText == 'ok'){
				reload();
			}else{
				alert(responseText);
			}
		}   
	};	
	
	var optionsCurrency = { 
		beforeSubmit:function(formData, jqForm, options){ 
						return true;
					},   
		success:function(responseText, statusText, xhr, $form){
			if(responseText == 'ok'){
				reload();
			}else{
				alert(responseText);
			}
		}   
	};	
	
	jQuery("#add_coin_packages_submit").live("submit",function(e){
		e.preventDefault(); // <-- important
		jQuery(this).ajaxSubmit(optionsCurrency);
		return false;
	});		
	jQuery("#currency_submit").live("submit",function(e){
		e.preventDefault(); // <-- important
		jQuery(this).ajaxSubmit(optionsCurrency);
		return false;
	});		
	jQuery("#edit_sport_submit").live("submit",function(e){
		e.preventDefault(); // <-- important
		jQuery(this).ajaxSubmit(optionsSport);
		return false;
	});	
	jQuery("#add_sport_submit").live("submit",function(e){
		e.preventDefault(); // <-- important
		jQuery(this).ajaxSubmit(optionsSport);
		return false;
	}); 
	jQuery("#add_team_submit").live("submit",function(e){
		e.preventDefault(); // <-- important
		jQuery(this).ajaxSubmit(optionsSport);
		return false;
	});
	jQuery("#edit_team_submit").live("submit",function(e){
		e.preventDefault(); // <-- important
		jQuery(this).ajaxSubmit(optionsSport);
		return false;
	});
	jQuery("#add_edit_category_submit").live("submit",function(e){
		e.preventDefault(); // <-- important
		jQuery(this).ajaxSubmit(optionsSport);
		return false;
	});
	jQuery("#add_edit_event_submit").live("submit",function(e){
		e.preventDefault(); // <-- important
		jQuery(this).ajaxSubmit(optionsCurrency);
		return false;
	});
});
 

function processAfterResponding(responseText, statusText, xhr, $form) {
	jQuery('#loader').hide();	
	 
	if(responseText == 'ok'){
		jQuery('#dialog').dialog('close');
		reload();
	}else{
		alert(responseText);
	}
}

function validateB4Submit(formData, jqForm, options){
	jQuery('#loader').show();
	
	json = {};
	for( e in formData){
		json[formData[e].name] = formData[e].value;
	}
	
	var arrayRequire = [ 'password','fullname','mobile']; 
	var err = 0;
	for(var i=0 ;i< arrayRequire.length; i++ ){
		if( isEmpty(json[arrayRequire[i]]) ){
			jQuery('#'+arrayRequire[i]+'_error').show();
			err++;
		}else{
			jQuery('#'+arrayRequire[i]+'_error').hide();
		}
	}
	
	if(err > 0){	
		jQuery('#loader').hide();
		alert("Error. Any fields are missing.");
		return false;
	}else{
		return true;
	}
}